from Bean.Person import Person

# 定义一个Map
mapdemo = {}
# 添加一个键值对
mapdemo[1] = "hello"
mapdemo[2] = "world"
# 访问map
print(mapdemo)
print(mapdemo[1])
# 修改字典中的值
newmap = mapdemo = {1: "hello world"}
print(newmap)
newmap[1] = str(newmap[1]) + 'world'
print(newmap)
newmap[1] = "test"
print(newmap[1])
# 删除键值对
mapdemo = {1: "hello", 2: "world"}
del mapdemo[1]
print(mapdemo)
# 遍历map
mapList = {}
ps = Person("彭于晏", "hefei", "pengyuyan@163.com", 13856088898)
for i in range(1, 10):
    mapList[i] = ps
print(mapList)
print(mapList.keys())  # 获取所有KEY
print(mapList.values())  # 获取所有vaules
for Person in mapList.values():
    print(Person.print_person())

for key, value in mapList.items():  # 获取键值对高效
    print("\n key :" + str(key))
    print("value :" + value.print_person())

# 排序
for key in sorted(mapList.keys()):
    print(mapList.get(key).print_person())
# 嵌套字典
userInfo = {"name": "tom", "age": 18}
userInfo_1 = {"name": "tomcat", "age": 19}
user = {"userid1": userInfo, "userid2": userInfo_1}
print(user)
for uid, usf in user.items():
    print(uid)
    print(usf)
